package api_models

import (
	"longmen/server/pkg/db/mysql/models/models_live"
	"longmen/server/pkg/db/mysql/models/models_main"
	"longmen/server/pkg/protobuf"
	"time"
)

type CheckIsMgrReq struct {
	Anchorid     int `json:"anchorid"`       //anchorid = 0 是否是全局管理員，非0  查看指定主播的管路員
	TargetUserID int `json:"target_user_id"` // 被操作目标用户id
}

type LiveConfigReq struct {
	Anchorid int `json:"anchorid" validate:"required"` //主播id
}

type LiveConfigResp struct {
	Config         LiveConfig `json:"config"`
	Nickname       string     `json:"nickname"`
	Liveid         int64      `json:"liveid"` //直播視別id
	Start          time.Time  `json:"start"`  //直播開始時間
	End            *time.Time `json:"end"`    //直播結束時間
	Heat           int        `json:"heat"`   //基礎熱度值
	Status         uint8      `json:"status"`
	Matchid        int        `json:"matchid"`
	OfficialType   int        `json:"official_type"`   //0:默认，1:官方直播间
	SumbumistegurK uint32     `json:"sumbumistegur_k"` //衰减系数K
	Populaarsuse   uint32     `json:"populaarsuse"`    //人气系数X
	GiftFactor     uint32     `json:"gift_factor"`     //礼物系数P
	GiftTime       uint32     `json:"gift_time"`       //礼物送出后的时长M（10分钟为一个单位M)
}

type LiveCalcReq struct {
	Anchorid          int   `json:"anchorid" validate:"required"`
	Liveid            int64 `json:"liveid" validate:"required"`
	BarrageHumanCount int64 `json:"barrage_human_count"` //弹幕人数
	BarrageTimeCount  int64 `json:"barrage_time_count"`  //弹幕总数
	ActiveViewer      int64 `json:"active_viewer"`       //活跃观众
	ViewerCount       int64 `json:"viewer_count"`        //总观众数
	HighCount         int64 `json:"high_count"`          //最高在线
	AvgLine           int64 `json:"avg_line"`            //平均在线
	HighHot           int64 `json:"high_hot"`            //最高人气值
	AvgHot            int64 `json:"avg_hot"`             //平均人气值
	Hot               int   `json:"hot"`                 //最終熱度
}

type LiveConfig struct {
	SumbumistegurK int `json:"sumbumistegur_k"` //衰减系数K
	Populaarsuse   int `json:"populaarsuse"`    //人气系数X
	GiftFactor     int `json:"gift_factor"`     //礼物系数P
	GiftTime       int `json:"gift_time"`       //礼物送出后的时长M（10分钟为一个单位M
}

type GetLiveInfoReq struct {
	Liveid int64 `json:"liveid" validate:"required"`
	Uid    int   `json:"uid"`
}

type GetHotLiveIReq struct {
	Uid int `json:"uid"`
}

type SetRoomMgrReq struct {
	Mgrid int `json:"mgrid" validate:"required"`
	Type  int `json:"type" validate:"required"` //0-取消 1-设置
}

type EditLiveReq struct {
	Liveid       string `json:"liveid" validate:"required"` //直播编号
	Title        string `json:"title" validate:"required"`
	Thumb        string `json:"thumb"`
	PullUrl      string `json:"pull_url"`
	Cateid       int    `json:"cateid" validate:"required"` //直播分类Id
	MatchId      int    `json:"match_id"`
	SportType    string `json:"sport_type"` //football,basket,tennis
	Ticket       int    `json:"ticket"`     //门票
	EnableWebrtc int32  `json:"enable_webrtc"`
}

type StartLiveReq struct {
	Title        string `json:"title" validate:"required"`
	Cateid       int    `json:"cateid" validate:"required"`
	Thumb        string `json:"thumb"`
	ThumbY       string `json:"thumb_y"`
	RoomType     int    `json:"room_type"`
	Pwd          string `json:"pwd"`
	Price        int    `json:"price"`
	StartStamp   int64  `json:"start_stamp"`
	MatchId      int    `json:"match_id"`
	AnchorSecret string `json:"anchor_secret"`                //varchar(255) DEFAULT NULL COMMENT '主播秘钥',
	SportType    string `json:"sport_type"`                   //football,basket,tennis
	Category     int    `json:"category" validate:"required"` //一级分类
	Ticket       int    `json:"ticket"`                       //门票
	EnableWebrtc int    `json:"enable_webrtc"`                // 1为启动
}

type GetListByCategoryReq struct {
	PageParam
	Categoryid int `json:"categoryid"`
}

type GetListByCategoryResp struct {
	List  []*LiveAnchor `json:"list"`
	Count int64         `json:"count"`
}

type LiveResp struct {
	models_live.Live
	Anchor *Anchor `json:"anchor"`
}

type Anchor struct {
	models_main.PartUser
	Profile        models_main.UserProfile `json:"profile"`
	Isattent       int                     `json:"isattent"`
	FansNum        int                     `json:"fans_num"` //粉丝数
	Hot            int                     `json:"hot"`
	IsSubscription int                     `json:"is_subscription"` //当前用户是否关注
	Living         uint8                   `json:"living"`          //直播中 0否 1是
}

type GetLivePageDataReq struct {
	Anchorid   int    `json:"anchorid"`
	Uid        int    `json:"uid"`
	DeviceInfo string `json:"device_info"`
	Platform   int8   `json:"platform"` // 注册来源  web-0; ios-1; android-2 3-H5
	Channel    string `json:"channel"`  // 用户渠道来源
}

type GetLivePageDataResp struct {
	Live            *models_live.Live `json:"live"`
	CateName        string            `json:"category_name"`
	Anchor          *Anchor           `json:"anchor"`
	RecLives        []*LiveResp       `json:"rec_lives"`
	FansCount       int               `json:"fans_count"`  //粉丝数量
	LiveNotice      string            `json:"live_notice"` //直播间公告
	UserLocal       string            `json:"user_local"`
	Math            *protobuf.Match   `json:"math"`
	LocalDb         string            `json:"local_db"`
	Advertising     string            `json:"advertising"` //广告词
	ContactName1    string            `json:"contact_name_1"`
	ContactAddress1 string            `json:"contact_address_1"`
	ContactName2    string            `json:"contact_name_2"`
	ContactAddress2 string            `json:"contact_address_2"`
	ContactName3    string            `json:"contact_name_3"`
	ContactAddress3 string            `json:"contact_address_3"`
	MainContent     string            `json:"main_content"`
}

type BanUserReq struct {
	Mgrid    int    `json:"mgrid" validate:"required"`
	Userid   int    `json:"userid" validate:"required"`   // 被禁用户
	Type     int    `json:"type"`                         // 1 禁言 0 解禁
	Anchorid int    `json:"anchorid" validate:"required"` // 0  全局禁言/解禁; 非0 為指定房間下禁言/解禁
	BanTime  int64  `json:"ban_time" validate:"required"` // 以秒为单位的要禁言他多久
	Reason   string `json:"reason" validate:"required"`   // 禁言原因
	BanType  int    `json:"ban_type"`                     //禁言原因编号
	BanMsg   string `json:"ban_msg"`                      //禁言的那条内容
}

type TimeBillingReq struct {
	Liveid int64 `json:"liveid" validate:"required"`
}

type LiveStreamHistoryView struct {
	Title          string  `json:"title" gorm:"column:title"`
	UserId         int64   `json:"-" gorm:"column:user_id"`
	LiveStreamer   string  `json:"liveStreamer" gorm:"column:nick_name"`
	LiveStreamId   int64   `json:"liveStreamId" gorm:"column:liveid"`
	LiveStreamerId int64   `json:"liveStreamerId" gorm:"column:anchorid"`
	LastVisitTime  *string `json:"lastVisitTime" gorm:"column:last_visit_time"`
	Thumb          string  `json:"thumb"` //直播封面
}

type GetLiveStreamHistoryReq struct {
	UserId        int64   `json:"userId"`
	StartTime     *string `json:"start_time"`
	EndTime       *string `json:"end_time"`
	PageNumber    int64   `json:"pageNumber" validate:"required"`
	AmountPerPage int64   `json:"amountPerPage" validate:"required"`
}

type LogLiveStreamHistoryReq struct {
	UserId   int64 `json:"userId" `
	AnchorId int64 `json:"anchorId" gorm:"column:anchorId" validate:"required"`
}

type GetLiveStreamHistoryResp struct {
	PageCount int64                    `json:"pageCount"`
	List      []*LiveStreamHistoryView `json:"list"`
}

type GetLeagueListReq struct {
	SportTypes string `json:"sportTypes"`
	StartTime  int64  `json:"start_time"`
	EndTime    int64  `json:"end_time"`
}

type GetLeagueListResp struct {
	Name string `json:"name" gorm:"column:name"` //
	Id   int64  `json:"id" gorm:"column:id"`     //
}

type GetMatchListReq struct {
	SportTypes string `json:"sportTypes"`
	LeagueIds  string `json:"leagueIds"`
	StartTime  int64  `json:"start_time"`
	EndTime    int64  `json:"end_time"`
}

type GetMatchListResp struct {
	Name       string  `json:"name" gorm:"column:name"`              //
	LeagueName string  `json:"leagueName" gorm:"column:league_name"` //
	SportType  int64   `json:"sportType" gorm:"column:sport_type_code"`
	Id         int64   `json:"id" gorm:"column:id"`           //
	Time       *string `json:"time" gorm:"column:timehelper"` //
}

type GetMgrListResp struct {
	models_live.LiveRoomManager
	User *Anchor `json:"user"`
}

type GetLiveScheduleListReq struct {
	UserId        int64 `json:"userId"`
	PageNumber    int64 `json:"pageNumber" validate:"required"`
	AmountPerPage int64 `json:"amountPerPage" validate:"required"`
}

type GetLiveScheduleList struct {
	LiveId       int64  `json:"liveid" gorm:"column:liveid"`
	Status       int64  `json:"status" gorm:"column:status"`
	ScheduleTime string `json:"scheduleTime" gorm:"column:schedule_time"`
	Title        string `json:"title" gorm:"column:title"`
	Profit       int64  `json:"profit" gorm:"column:profit"`
	StreamLinkPC string `json:"streamLinkPC" gorm:"column:pushurl1"`
	PlayedTime   int    `json:"playedTime" gorm:"column:played_time"`
	StartTime    string `json:"startTime" gorm:"column:start_time"`
	EndTime      string `json:"endTime" gorm:"column:end_time"`
	RowCount     int    `json:"-" gorm:"column:row_count"`
}

type GetLiveScheduleListResp struct {
	List  []*GetLiveScheduleList `json:"list"`
	Count int64                  `json:"count"`
}

type GetLiveScheduleReq struct {
	UserId int64 `json:"userId"`
	LiveId int64 `json:"liveid"`
}

type GetLiveScheduleResp struct {
	LiveId       int64  `json:"liveid" gorm:"column:liveid"`
	SportType    int    `json:"sportType" gorm:"column:sport_type"`
	MatchId      int64  `json:"matchId"`
	ScheduleTime string `json:"scheduleTime"`
	StartTime    string `json:"startTime" gorm:"column:start_time"`
	EndTime      string `json:"endTime" gorm:"column:end_time"`
	Introduction string `json:"introduction"`
	UseVideo     int    `json:"useVideo" gorm:"column:use_video"`

	Title    string `json:"title"`
	Cateid   int    `json:"cateid" gorm:"column:categoryid"`
	PullUrl  string `json:"pullUrl"`
	Stream   string `json:"stream"`
	Thumb    string `json:"thumb"`
	RoomType int    `json:"roomType"`
	Pwd      string `json:"pwd" gorm:"column:password"`
	Price    int    `json:"price"`
}

type StartLiveScheduleReq struct {
	LiveId     int64  `json:"liveid" gorm:"column:liveid" validate:"required"`
	PullUrl    string `json:"pull_url" validate:"required"`
	Stream     string `json:"stream" validate:"required"`
	StreamName string `json:"stream_name"`
}

type GetLiveListReq struct {
	PageParam
	Categoryid int `json:"categoryid" validate:"required" example:"1"` // 二级子类
	CateID     int `json:"cateid"`                                     // 大类
	UID        int `json:"uid"`
}

type GetStreamInfoResp struct {
	Stream        string `json:"stream"`           //流名
	PushUrl       string `json:"push_url"`         //推流地址
	WebRtcPushUrl string `json:"web_rtc_push_url"` //WebRtc推流地址
	PullUrl       string `json:"pull_url"`         //播放地址
	FlvPushUrl    string `json:"flv_push_url"`
	AnchorSecret  string `json:"anchor_secret"` //主播的秘钥
}
type GetStreamInfoByStreamReq struct {
	Stream string `json:"stream"` //流名
}
type GetContributeRankReq struct {
	Anchorid int64 `json:"anchorid" validate:"required"`
	Type     int64 `json:"type"` //0 日榜 1 周榜
}

type GetContributeRankResp struct {
	Id       int   `json:"id" gorm:"primaryKey;autoIncrement"`
	Uid      int   `json:"uid"`
	Anchorid int   `json:"anchorid"`
	Liveid   int64 `json:"liveid"`
	Intimacy int   `json:"intimacy"` //sum(spend)
	User     struct {
		Uid      int    `json:"id"`
		NickName string `json:"nick_name"`
		Avatar   string `json:"avatar"`
	} `json:"user"`
}

type LiveStatisticReq struct {
	Type     string `json:"type" validate:"required"` //active:活跃观众 visit:总观众数 online:最高在线 chat:弹幕
	Uid      string `json:"uid"`
	Liveid   int64  `json:"liveid" validate:"required"`
	ChatTime string `json:"chat_time"` //YYYYMMDDHHMI type是chat時要傳
	Ip       string `json:"-"`
}

type LiveCallbackReq struct {
	Appid        int    `json:"appid"`         //用户 APPID
	App          string `json:"app"`           //推流域名
	Appname      string `json:"appname"`       //推流路径
	StreamId     string `json:"stream_id"`     //直播流名称
	ChannelId    string `json:"channel_id"`    //同直播流名称
	EventTime    int64  `json:"event_time"`    //事件消息产生的 UNIX 时间戳
	EventType    int    `json:"event_type"`    //1:直播推流 0:直播断流
	Sequence     string `json:"sequence"`      //消息序列号，标识一次推流活动，一次推流活动会产生相同序列号的推流和断流消息
	Node         string `json:"node"`          //直播接入点的 IP
	UserIp       string `json:"user_ip"`       //用户推流 IP
	StreamParam  string `json:"stream_param"`  //用户推流 URL 所带参数
	PushDuration string `json:"push_duration"` //断流事件通知推流时长，单位毫秒
	Errcode      int    `json:"errcode"`       //推断流错误码
	Errmsg       string `json:"errmsg"`        //推断流错误描述  https://cloud.tencent.com/document/product/267/35256#erro_code
	SetId        int    `json:"set_id"`        //判断是否为国内外推流。1-6为国内，7-200为国外
	Width        int    `json:"width"`         //视频宽度，最开始推流回调的时候若视频头部信息缺失，可能为0
	Height       int    `json:"height"`        //视频高度，最开始推流回调的时候若视频头部信息缺失，可能为0
	Sign         string `json:"sign"`
	T            int64  `json:"t"`
}

type BandedUserIds struct {
	Ids []int `json:"ids"` //被禁言的用戶id數組
}

type GetHotRecommendLiveReq struct {
	Categoryid int `json:"categoryid"` //1-足球,2-篮球,13-娱乐
}
type PushNotifyResp struct {
	Code int `json:"code"` // 0-未推流,1-已推流
}
type PushNotifyReq struct {
	Stream string `json:"stream"` //流名（流Id）
}

type OfficialTypeLiveReq struct {
	AnchorID int `json:"anchor_id" validate:"required"`
}

type OfficialLive struct {
	MatchID      int    `json:"match_id"`       //赛事id
	EventID      int    `json:"event_id"`       //联赛名称
	MatchTime    int    `json:"match_time"`     //开赛时间
	HomeID       int    `json:"home_id"`        //主队ID
	HomeTeamName string `json:"home_team_name"` //主队名称
	HomeScore    int    `json:"home_score"`     //主队当前比分
	AwayID       int    `json:"away_id"`        //客队ID
	AwayTeamName string `json:"away_team_name"` //主队名称
	AwayScore    int    `json:"away_score"`     //客队当前比分
}

type OfficialTextLive struct {
	Timeline string `json:"timeline"` //时间线
	Text     string `json:"text"`     //内容
}

type BaseOdds struct {
	MatchID    int     `json:"match_id"` //赛事id
	Type       string  `json:"type"`     //bs-大小球 asia-亚盘 eu-欧赔
	Value1     float32 `json:"value1"`
	Value2     float32 `json:"value2"`
	Value3     float32 `json:"value3"`
	ChangeTime int     `json:"change_time"`
}

type OfficialMatchOdd struct {
	Begin struct {
		Asia BaseOdds `json:"asia"` // 让球
		EU   BaseOdds `json:"eu"`   // 胜负
		BS   BaseOdds `json:"bs"`   // 大小球
	} `json:"begin"` //初始指数

	Immediate struct {
		Asia BaseOdds `json:"asia"` // 让球
		EU   BaseOdds `json:"eu"`   // 胜负
		BS   BaseOdds `json:"bs"`   // 大小球
	} `json:"immediate"` //即时指数

	Current struct {
		Asia BaseOdds `json:"asia"` // 让球
		EU   BaseOdds `json:"eu"`   // 胜负
		BS   BaseOdds `json:"bs"`   // 大小球
	} `json:"current"` //赛中指数
}

type OfficialTeamDetail struct {
	HomeTeam struct {
		ID      int    `json:"id"`
		Name    string `json:"name"` //队名
		Logo    string `json:"logo"` //队标
		Players []struct {
			Name     string `json:"name"`
			Position string `json:"position"` //球员岗位定位
			Avatar   string `json:"avatar"`   //头像
		} `json:"players"`
	} `json:"home_team"` //主队

	AwayTeam struct {
		ID      int    `json:"id"`
		Name    string `json:"name"` //队名
		Logo    string `json:"logo"` //队标
		Players []struct {
			Name     string `json:"name"`
			Position string `json:"position"` //球员岗位定位
			Avatar   string `json:"avatar"`   //头像
		} `json:"players"`
	} `json:"away_team"` //客队
}

type Category struct {
	Id    int    `json:"id" gorm:"primaryKey;autoIncrement"`
	Title string `json:"title"` //varchar(255) DEFAULT NULL,
	Icon  string `json:"icon"`  // varchar(255) DEFAULT NULL,
}

type LiveBigCategory struct {
	Category     int
	CategoryName string
	Icon         string `json:"icon"`
	CategoryList []*Category
}

type LiveVisitRecordReq struct {
	LiveID   int `json:"live_id" validate:"required"`
	Platform int `json:"platform" validate:"required"` //1:web, 2:ios, 3:android
}

type LiveVisitRecordResp struct {
	Status int `json:"status"` //1 成功, 2失败
}

type LiveVisitListReq struct {
	UserID int `json:"user_id" validate:"required"`
	Page   int `json:"page" validate:"required"`
	Size   int `json:"size" validate:"required"`
	Status int `json:"status" validate:"required"` //1 全部, 2直播中
}

type RecommendAnchorReq struct {
	Size uint32 `json:"size"`
}

type LiveIDIncome struct {
	Liveid       int64 `json:"live_id"`
	Income       int   `json:"income"`        //主播本场次收入钻石,
	EagleDiamond int   `json:"eagle_diamond"` //主播本场次收入鹰钻,
	SpendType    int32 `json:"spend_type"`
}

type LiveIDGiftNum struct {
	Liveid  int64 `json:"liveid"`
	GiftNum int64 `json:"gift_num"`
}

type LiveIDVisitorNum struct {
	Liveid     int64 `json:"liveid"`
	VisitorNum int64 `json:"visitor_num"`
}

type DirtyWords struct {
	OpType int      `json:"op_type"` // 0 删除 1增加
	Words  []string `json:"words"`   // 词语
}

// 这个结构是管理员删消息时 ->gprc（格式与nats不同） ->在这里转化->nats
type ClearChatMessage struct {
	ChatId int `json:"chat_id"`
	UserId int `json:"user_id"`
	RoomId int `json:"room_id"`
}

type LiveInfo struct {
	Title        string `json:"title"`
	Thumb        string `json:"thumb"`
	PullUrl      string `json:"pull_url"`
	Categoryid   uint32 `json:"categoryid"`
	AnchorAvatar string `json:"anchor_avatar"`
	AnchorName   string `json:"anchor_name"`
	Category     uint32 `json:"category"`
	Hot          uint32 `json:"hot"`
	Anchorid     uint32 `json:"anchorid"`
	Matchid      uint32 `json:"matchid"`
	Tag          int64  `json:"tag"`
	TagTitle     string `json:"tag_title" gorm:"-"`
	TagColor     string `json:"tag_color" gorm:"-"`
	TagPoint     int32  `json:"tag_point" gorm:"-"`
	TagType      int32  `json:"tag_type" gorm:"-"`
	GuessTag     int    `json:"guess_tag"` //如果是0表示没有竞猜，1表示有
}

type EntryExitStruct struct {
	Uid       int   `json:"uid"`
	Duration  int64 `json:"duration"`  //时长
	IOTimes   int   `json:"ioTimes"`   //进出次数
	EntryTime int64 `json:"entryTime"` //进入时间
	ExitTime  int64 `json:"exitTime"`  //退出时间
	IsSysUser uint8 `json:"isSysUser"` //是否系统用户
	OutDeal   bool  `json:"outDeal"`   //out请求是否处理过
	Platform  int   `json:"platform"`  //设备
}

type LivePlugins struct {
	LiveStatus     int
	PullUrl        string
	PullFlvUrl     string
	Platform       int
	PlayFromSource int32
	ReplyVideo     int32
	SkipTime       int32
}

type LiveRecordCallReq struct {
	EventType       string `json:"EventType"` //NewFileUpload
	FileUploadEvent struct {
		FileId   string `json:"FileId"` //文件id存起来，删除视频回调时会带过来
		MetaData struct {
			Duration float64 `json:"Duration"`
		}
		MediaBasicInfo struct {
			Name          string        `json:"Name"`
			Description   string        `json:"Description"`
			CreateTime    time.Time     `json:"CreateTime"`
			UpdateTime    time.Time     `json:"UpdateTime"`
			ExpireTime    time.Time     `json:"ExpireTime"`
			ClassId       int           `json:"ClassId"`
			ClassName     string        `json:"ClassName"`
			ClassPath     string        `json:"ClassPath"`
			CoverUrl      string        `json:"CoverUrl"`
			Type          string        `json:"Type"`
			MediaUrl      string        `json:"MediaUrl"`
			TagSet        []interface{} `json:"TagSet"`
			StorageRegion string        `json:"StorageRegion"`
			SourceInfo    struct {
				SourceType    string `json:"SourceType"`
				SourceContext string `json:"SourceContext"`
			} `json:"SourceInfo"`
			Size int    `json:"Size"`
			Vid  string `json:"Vid"`
		} `json:"MediaBasicInfo"`
		ProcedureTaskId        string `json:"ProcedureTaskId"`
		ReviewAudioVideoTaskId string `json:"ReviewAudioVideoTaskId"`
	} `json:"FileUploadEvent"`
}

type ActivityReq struct {
	AnchorID int `json:"anchor_id"`
}
